﻿// ***********************************************************************
// 程 序 集  : HdhNetQuery
// 建立时间  : 2025-09
// 类库说明  ：通用数据库操作接口MySql Mssql PostgerSql Sqlite
// 个人网站  ：http://www.hdhcms.com 
// ***********************************************************************
// <copyright>
//     Copyright by He DongHua(何冬华) All, QQ群:876705805 QQ:664627440 Email:664627440@qq.com
// </copyright>
// 如果要使用当前代码，请保存这些信息
// ***********************************************************************
using System.Data;

namespace HdhNetQuery
{
    public interface IHdhcmsHelper
    {
        string? strConn { get; }
        /// <summary>
        /// 返回连接字符串
        /// </summary>
        /// <returns></returns>
        string? GetConnString();
        /// <summary>
        /// 增、删、改的专用执行方法 
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="param">参数数组</param>
        /// <returns>操作受影响的行数</returns>
        /// <exception cref="Exception">抛出的异常</exception>
        int ExecuteNonQuery(string sql, object[]? param = null);
        /// <summary>
        /// 插入数据并返回最新的自动编号ID
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="param">参数数组</param>
        /// <returns>返回当前插入数据的自动编号</returns>
        /// <exception cref="Exception">抛出的异常</exception>
        int InsertDataGetAutoId(string sql, object[]? param = null);
        /// <summary>
        /// 聚合查询返回单一结果
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="param">参数数组</param>
        /// <returns>返回当前聚合查询的结果</returns>
        /// <exception cref="Exception">抛出的异常</exception>
        object ExecuteScalar(string sql, object[]? param = null);
        /// <summary>
        /// 获取一个DATATABLE查询结果集
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="param">参数数组</param>
        /// <returns>返回DataTable对象</returns>
        /// <exception cref="Exception">抛出的异常</exception>
        DataTable GetDataTable(string sql, object[]? param = null);
        /// <summary>
        /// 返回DATASET，用0,1,2,3区分不同的DATATABLE
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns>返回DataSet对象</returns>
        /// <exception cref="Exception">抛出的异常</exception>
        DataSet GetDataSet(string sql, object[]? param = null);
        /// <summary>
        /// 返回多个可命名DataTable的DATASET
        /// </summary>
        /// <param name="sqlDic">语句字典，包括名称及语句</param>
        /// <param name="dicParam">参数字典，期中key与语句字典的key一致</param>
        /// <returns>返回DataSet对象</returns>
        /// <exception cref="Exception">抛出的异常</exception>
        DataSet GetDataSet(Dictionary<string, string> sqlDic, Dictionary<string, object[]>? dicParam = null);
        /// <summary>
        /// 通过事务批量执行SQL查询语句
        /// </summary>
        /// <param name="sqlList">语句语句集合</param>
        /// <returns>成功返回TRUE，否则FALSE</returns>
        string ExecuteNonQueryTrans(List<string> sqlList);
        /// <summary>
        /// 通过事务批量执行SQL查询语句，有参数时要全部都有，参数要对等
        /// </summary>
        /// <param name="sqlList"></param>
        /// <param name="paran">参数必填，必须与sqlList形成对应的关系 </param>
        /// <returns></returns>
        string ExecuteNonQueryTrans(List<string> sqlList, List<object[]>? paran=null);
        /// <summary>
        /// 根据查询结果返回List集合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="hdhSql"></param>
        /// <param name="paran"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        List<T> GetQueryList<T>(string hdhSql, object[]? paran=null) where T : new();
        /// <summary>
        /// 根据查询返回Model
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="hdhSql"></param>
        /// <param name="paran"></param>
        /// <returns>返回Model</returns>
        /// <exception cref="Exception"></exception>
        T GetQueryModel<T>(string hdhSql, object[]? paran = null) where T : new();
        /// <summary>
        /// 查询获取DataReader对象
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="param">参数数组 SQLiteParameter类型</param>
        /// <returns>返回一个DataReader对象</returns>
        /// <exception cref="Exception">抛出的异常</exception>
        object GetExecuteReader(string sql, object[]? param = null);
        /// <summary>
        /// 表是否存在
        /// </summary>
        /// <param name="TableName"></param>
        /// <returns></returns>
        bool TableExists(string TableName);
        /// <summary>
        /// 表的字段是否存在
        /// </summary>
        /// <param name="TableName">表名</param>
        /// <param name="FieldName">字段表</param>
        /// <returns></returns>
        bool TableFieldExists(string TableName, string FieldName);
    }
}
